<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Api\Controllers\Commons;

use App\Api\BaseApi;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class UploadApi extends BaseApi
{
    public function uploadPhoto()
    {
        $request = self::validate([
            'photo' => 'required|file|image|max:5120',
        ]);
        $key = sprintf('user_%d_avatar', self::UserId());
        $path = $request->file('photo')->store($key, 'public');
        return responses(['path' => "{$path}"]);
    }

    public function genQrcode()
    {
        $request = self::validate([
            'content' => 'required',
        ]);
        $content = $request->get('content');
        $size = $request->get('size', 600);
        $color = $request->get('color', [0, 0, 0]);

        $res = QrCode::size($size)->encoding('UTF-8')->color(...$color)->generate($content);
        return response($res);
    }
}
